﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HCQ2_Model.ViewModel.WebAPI;
using HCQ2_Common.Constant;
using HCQ2_Model.Data;

namespace HCQ2WebAPI_Logic.Model
{
    /// <summary>
    ///  WebApi返回模型
    /// </summary>
    public class ApiResultJsonModel
    {
        /// <summary>
        ///  返回对象
        /// </summary>
        /// <param name="errcode">代码</param>
        /// <param name="errmsg">消息</param>
        /// <param name="value">返回值</param>
        /// <returns></returns>
        public static WebApiResultJsonModel RedirectWebApi(int errcode, string errmsg, object value)
        {
            return new  WebApiResultJsonModel
            {
                errcode = errcode,
                errmsg = errmsg,
                value = value
            };
        }

        /// <summary>
        ///  返回成功
        /// </summary>
        /// <returns></returns>
        public static WebApiResultJsonModel Ok()
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Ok,
                errmsg = string.Empty,
                value = null
            };
        }
        /// <summary>
        ///  返回成功
        /// </summary>
        /// <param name="errmsg">返回消息</param>
        /// <param name="value">返回数据</param>
        /// <returns></returns>
        public static WebApiResultJsonModel Ok(string errmsg, object value)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Ok,
                errmsg = errmsg,
                value = value
            };
        }
        /// <summary>
        ///  返回成功
        /// </summary>
        /// <param name="errmsg">消息</param>
        /// <returns></returns>
        public static WebApiResultJsonModel Ok(string errmsg)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Ok,
                errmsg = errmsg,
                value = null
            };
        }
        /// <summary>
        ///  返回异常：不需要记录日志
        /// </summary>
        /// <param name="errmsg"></param>
        /// <returns></returns>
        public static WebApiResultJsonModel Exception(string errmsg)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Exception,
                errmsg = errmsg,
                value = null
            };
        }
        /// <summary>
        ///  返回错误：需要记录日志
        /// </summary>
        /// <param name="errmsg"></param>
        /// <returns></returns>
        public static WebApiResultJsonModel Error(string errmsg)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Error,
                errmsg = errmsg,
                value = null
            };
        }
    }
    /// <summary>
    ///  WebApi返回模型泛型版本
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ApiResultJsonModel<T>
    {
        /// <summary>
        ///  返回对象
        /// </summary>
        /// <param name="errcode">代码</param>
        /// <param name="errmsg">消息</param>
        /// <param name="value">返回值</param>
        /// <returns></returns>
        public static WebApiResultJsonModel<T> RedirectWebApi(int errcode, string errmsg, T value)
        {
            return new WebApiResultJsonModel<T>
            {
                errcode = errcode,
                errmsg = errmsg,
                value = value
            };
        }

        /// <summary>
        ///  返回成功
        /// </summary>
        /// <returns></returns>
        public static WebApiResultJsonModel Ok()
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Ok,
                errmsg = string.Empty,
                value = null
            };
        }
        /// <summary>
        ///  返回成功
        /// </summary>
        /// <param name="errmsg">返回消息</param>
        /// <param name="value">返回数据</param>
        /// <returns></returns>
        public static WebApiResultJsonModel Ok(string errmsg, T value)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Ok,
                errmsg = errmsg,
                value = value
            };
        }
        /// <summary>
        ///  返回成功
        /// </summary>
        /// <param name="errmsg">消息</param>
        /// <returns></returns>
        public static WebApiResultJsonModel Ok(string errmsg)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Ok,
                errmsg = errmsg,
                value = null
            };
        }
        /// <summary>
        ///  返回异常：不需要记录日志
        /// </summary>
        /// <param name="errmsg"></param>
        /// <returns></returns>
        public static WebApiResultJsonModel Exception(string errmsg)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Exception,
                errmsg = errmsg,
                value = null
            };
        }
        /// <summary>
        ///  返回错误：需要记录日志
        /// </summary>
        /// <param name="errmsg"></param>
        /// <returns></returns>
        public static WebApiResultJsonModel Error(string errmsg)
        {
            return new WebApiResultJsonModel
            {
                errcode = WebResultCode.Error,
                errmsg = errmsg,
                value = null
            };
        }
    }
}
